<template>
    <div class="apply">
        <!-- <TitleItem v-if="this.wx==true"></TitleItem> -->
        <!-- <div class="nav-bar-box">
			<van-nav-bar title="活动详情" left-text="返回" left-arrow fixed @click-left="$router.go(-1)">
			</van-nav-bar>
		</div> -->
        <div class="padding">
            <van-cell-group>
                <van-field v-model="listQuery.username" label="姓名" placeholder="请输入用户名" />
                <van-field onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" v-model="listQuery.phone" maxlength="11" label="手机号" placeholder="请输入手机号" />
                <!-- <van-field v-model="username" label="部门" placeholder="请输入所在部门" /> -->
            </van-cell-group>
        </div>
        <div class="base">
            <div class="base-btn" @click="apply">
                <p>确定</p>
            </div>
        </div>

    </div>
</template>
<script>
import { activity_applyActivity } from "@/api/activity";
import TitleItem from "../../components/public/title/title";
export default {
  name: "Apply",
  components: { TitleItem },
  data() {
    return {
      listQuery: {
        username: "",
        phone: "",
        active_id: this.$route.query.active_id,
        company_id: localStorage.getItem("companyId") - 0
      }
    };
  },
  methods: {
    apply() {
      this.saveObj();
    },
    async saveObj() {
      if (!this.listQuery.username) {
        this.$toast("姓名不能为空");
        return;
      }
      if (!this.listQuery.phone) {
        this.$toast("手机号不能为空");
        return;
      }
      let user = JSON.parse(localStorage.getItem("user"));
      let query = Object.assign({}, this.listQuery, { user_id: user.id });
      let res = await activity_applyActivity(query);
      if (res.data.status == 100) {
        this.$toast.success("报名成功");
        this.listQuery = {};
      }
    }
  },
  created() {
  }
};
</script>
<style lang="scss" scoped>
@import "Apply";
</style>
